package com.alander.nexusgo.framework.log.starter.autoconfigure;

import com.alander.nexusgo.framework.log.starter.aspect.LogStatAspect;
import com.alander.nexusgo.framework.log.starter.service.LogStatService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(LogStatProperties.class)
@ConditionalOnProperty(prefix = "log.stat", name = "enabled", havingValue = "true", matchIfMissing = true)
public class LogStatAutoConfiguration {

    @Bean
    public LogStatAspect logStatAspect(LogStatProperties properties, LogStatService logStatService) {
        return new LogStatAspect(properties, logStatService);
    }

    @Bean
    public LogStatService logStatService() {
        return new LogStatService();
    }
}
